home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung CD 2 (Tewi)(1994).iso / doc / mir / ebc_asc.c < prev    next >
Text File  |  1992-07-02  |  6KB  |  183 lines

  1. /*
  2.  *  usage:  ebc_asc  ebcdic_input  ascii_output
  3.  *
  4.  *  EBC_ASC Converts an EBCDIC file to ASCII.  EBCDIC (Extended Binary
  5.  *          Coded Decimal Interchange Code) data is commonly produced
  6.  *          by IBM mainframe computers.  ASCII (American Standard Code
  7.  *          for Information Interchange) is used on personal computers
  8.  *          and computers produced by the majority of manufacturers.
  9.  *
  10.  *  input:  Any EBCDIC file
  11.  *
  12.  *  output: ASCII equivalent
  13.  *
  14.  *  writeup: MIR TUTORIAL ONE, topic 4
  15.  *
  16.  *  Written:    Douglas Lowry   Feb 17 92
  17.  *              Copyright (C) 1992 Marpex Inc.
  18.  *
  19.  *    The MIR (Mass Indexing and Retrieval) Tutorials explain detailed
  20.  *    usage and co-ordination of the MIR family of programs to analyze,
  21.  *    prepare and index databases (small through gigabyte size), and
  22.  *    how to build integrated retrieval software around the MIR search
  23.  *    engine.  The fifth of the five MIR tutorial series explains how
  24.  *    to extend indexing capability into leading edge search-related
  25.  *    technologies.  For more information, GO IBMPRO on CompuServe;
  26.  *    MIR files are in the DBMS library.  The same files are on the
  27.  *    Canada Remote Systems BBS.  A diskette copy of the Introduction
  28.  *    is available by mail ($10 US... check, Visa or Mastercard);
  29.  *    diskettes with Introduction, Tutorial ONE software and the
  30.  *    shareware Tutorial ONE text cost $29.  Shareware registration
  31.  *    for a tutorial is also $29.
  32.  *
  33.  *    E-mail...
  34.  *                Compuserve  71431,1337
  35.  *                Internet    doug.lowry%canrem.com
  36.  *                UUCP        canrem!doug.lowry
  37.  *                Others:     doug.lowry@canrem.uucp
  38.  *
  39.  *    FAX...                  416 963-5677
  40.  *
  41.  *    "Snail mail"...         Douglas Lowry, Ph.D.
  42.  *                            Marpex Inc.
  43.  *                            5334 Yonge Street, #1102
  44.  *                            North York, Ontario
  45.  *                            Canada  M2N 6M2
  46.  *
  47.  *    Related database consultation and preparation services are
  48.  *    available through:
  49.  *              Innotech Inc., 2001 Sheppard Avenue E., Suite #118,
  50.  *              North York, Ontario  Canada   M2J 4Z7
  51.  *              Tel.  416 492-3838   FAX  416 492-3843
  52.  *
  53.  *  This program is free software; you may redistribute it and/or
  54.  *  modify it under the terms of the GNU General Public License as
  55.  *  published by the Free Software Foundation; either version 2 of
  56.  *  the License, or (at your option) any later version.
  57.  *
  58.  *  This program is distributed in the hope that it will be useful,
  59.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  60.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  61.  *  GNU General Public License for more details.
  62.  *
  63.  *  You should have received a copy of the GNU General Public License
  64.  *  (file 05LICENS) along with this program; if not, write to the
  65.  *  Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  66.  *  USA.
  67.  */
  68.  
  69. #include <stdio.h>
  70.  
  71. #define     repeat      for(;;)
  72. #define     MAX_BYTES   2048
  73.  
  74. /*
  75.  * declarations 
  76.  */
  77.  
  78. typedef     enum        _bool
  79.              { FALSE = 0, TRUE = 1 }  Bool;
  80.  
  81.     void        Usage_(), process();
  82.     char        *Cmdname_() {    return( "ebc_asc" );  }
  83.  
  84. /*
  85.  * MAIN
  86.  */
  87.  
  88. main( argc, argv )
  89.     int  argc;
  90.     char **argv;
  91. {
  92.     FILE    *fp, *fp_out ;
  93.     char    c10 ;
  94.  
  95.     if( argc != 3 )
  96.         Usage_() ;
  97.     c10 = argv[1][0] ;
  98.     if( c10 == '-' || c10 == '/' || c10 == '?' )
  99.         Usage_() ;
  100.  
  101.     if(( fp = fopen( argv[1], "rb" )) == NULL )
  102.     {
  103.         fprintf( stderr, "\nUnable to open file %s.\n", argv[1] );
  104.             Usage_();
  105.     }
  106.  
  107.     if(( fp_out = fopen( argv[2], "wb" )) == NULL )
  108.     {
  109.         fprintf( stderr, "\nUnable to open file %s.\n", argv[2] );
  110.             Usage_();
  111.     }
  112.  
  113.     process( fp, fp_out ) ;
  114.  
  115.     fclose( fp );
  116.     fclose( fp_out );
  117.     exit( 0 );
  118. }
  119. /*
  120.  *  Usage
  121.  */
  122.     void
  123. Usage_()
  124. {
  125.     fprintf( stderr,
  126. "\nUsage:  %s  ebcdic_input  ascii_output\n\n\
  127.         Converts an EBCDIC file to ASCII.  EBCDIC (Extended Binary\n\
  128.         Coded Decimal Interchange Code) data is commonly produced\n\
  129.         by IBM mainframe computers.  ASCII (American Standard Code\n",
  130.             Cmdname_() );
  131.     fprintf( stderr,
  132. "        for Information Interchange) is used on personal computers\n\
  133.         and computers produced by the majority of manufacturers.\n\n\
  134. input:  Any EBCDIC file\n\n\
  135. output: ASCII equivalent\n\n\
  136. writeup: MIR TUTORIAL ONE, topic 4\n\n" ) ;
  137.     exit( 1 ) ;
  138. }
  139. /*
  140.  *  PROCESS
  141.  */
  142.     void
  143. process( fp_in, fp_out )
  144.     FILE    *fp_in, *fp_out ;
  145. {
  146.     short   table[ 256 ] = {
  147.     0,  1,  2,  3,156,  9,134,127,151,141,142, 11, 12, 13, 14, 15,
  148.    16, 17, 18, 19,157,133,  8,135, 24, 25,146,143, 28, 29, 30, 31,
  149.   128,129,130,131,132, 10, 23, 27,136,137,138,139,140,  5,  6,  7,
  150.   144,145, 22,147,148,149,150,  4,152,153,154,155, 20, 21,158, 26,
  151.    32,160,161,162,163,164,165,166,167,168, 91, 46, 60, 40, 43, 33,
  152.    38,169,170,171,172,173,174,175,176,177, 93, 36, 42, 41, 59, 94,
  153.    45, 47,178,179,180,181,182,183,184,185,124, 44, 37, 95, 62, 63,
  154.   186,187,188,189,190,191,192,193,194, 96, 58, 35, 64, 39, 61, 34,
  155.   195, 97, 98, 99,100,101,102,103,104,105,196,197,198,199,200,201,
  156.   202,106,107,108,109,110,111,112,113,114,203,204,205,206,207,208,
  157.   209,126,115,116,117,118,119,120,121,122,210,211,212,213,214,215,
  158.   216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,
  159.   123, 65, 66, 67, 68, 69, 70, 71, 72, 73,232,233,234,235,236,237,
  160.   125, 74, 75, 76, 77, 78, 79, 80, 81, 82,238,239,240,241,242,243,
  161.    92,159, 83, 84, 85, 86, 87, 88, 89, 90,244,245,246,247,248,249,
  162.    48, 49, 50, 51, 52, 53, 54, 55, 56, 57,250,251,252,253,254,255 } ;
  163.  
  164.     unsigned char   buf[ MAX_BYTES ],
  165.                     out;
  166.     int             len, i ;
  167.  
  168.     while(( len = fread( buf, sizeof( char ), MAX_BYTES, fp_in )) > 0 )
  169.     {
  170.         for( i = 0; i < len ; i++ )
  171.         {
  172.             out = table[ buf[ i ] ];
  173.             if( fputc( out, fp_out ) != out )
  174.             {
  175.                 fprintf( stderr, "FATAL... Unable to write.\n\n" ) ;
  176.                 exit( 1 ) ;
  177.             }
  178.         }
  179.     }
  180.  
  181.     return ;
  182. }
  183.